#include <iostream>

using namespace std;

double Production(int a, int b);
double Permutation(int n, int m);
double Combination(int n, int m);

int main()
{
    cout << "Please enter two integers n,m (0 <= m <= n)"
            " and an operator ('p' for permutation,'c' for conbination)\n";
    int n, m;
    char op;
    while (cin >> n >> m >> op)
    {
        if (m < 0 || m > n)
        {
            std::cerr << "m must be between 0 and n" << endl;
            continue;
        }
        if (op != 'p' && op != 'c')
        {
            cerr << "operator must be 'p' or 'c'" << endl;
            continue;
        }
        cout << (op == 'p' ? Permutation(n, m) : Combination(n, m)) << endl;
    }
    return 0;
}

double Production(int a, int b)
{
    double p = 1;
    while (a <= b)
    {
        p *= a++;
    }
    return p;
}

double Permutation(int n, int m)
{
    return Production(n - m + 1, n);
}
double Combination(int n, int m)
{
    return Permutation(n, m) / Production(1, m);
}